package js.dwim.domain;

import java.io.Serializable;

import com.google.appengine.api.datastore.Key;

import javax.jdo.annotations.IdGeneratorStrategy;
import javax.jdo.annotations.PersistenceCapable;
import javax.jdo.annotations.Persistent;
import javax.jdo.annotations.PrimaryKey;

@PersistenceCapable( detachable = "true" )
public class Player
        implements Serializable, Comparable<Player>
{
	private static final long serialVersionUID 	= 1L;

    @Persistent
    public static final String AI_PLAYER 		= "AI";
    
    @PrimaryKey
    @Persistent( valueStrategy = IdGeneratorStrategy.IDENTITY )
    private Key key;

    @Persistent
    private String name;
    
    @Persistent
    private int funds;

    public Player( String name )
    {
        this.name 	= name;
        this.setFunds(5);
    }
    
	public boolean equals( Object target ) 
	{
		return ( target instanceof Player
				&& ( (Player)target ).key.equals( this.key ) );
	}
	
	public int compareTo( Player target ) 
	{
		return this.key.compareTo( target.key );
	}

    public Key getKey()
    {
        return key;
    }

    public String getName()
    {
        return name;
    }

    public void setName( String name )
    {
        this.name = name;
    }

	public void setFunds( int funds ) 
	{
		this.funds = funds;
	}

	public int getFunds() 
	{
		return funds;
	}
}